<?php
	include('includes/start_session.php');
	include('includes/user_courses.php');
	include('db-api/txt-db-api.php');
	
	if(user_found() && isset($_POST['courses']))
	{
		$db = new Database('Eclass');
	
		$checks = array();
		$checks = $_POST['courses'];
		
		$any_chosen = false;
		foreach($checks as $check)
		{
			$any_chosen = true;
			$query = 'INSERT INTO UsersCourses VALUES';
			$query = $query . ' (\'' . $_SESSION['username'] . '\', ' . $check . ', \'false\')';
			$db->executeQuery($query);
		}
		if($any_chosen == false)
			header('Location: register_courses.php?message=1');
		else
			header('Location: register_courses.php?message=2');
	}
	else
		header('Location: register_courses.php?message=1');
?>